package homework8;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Arrays;

public class Sort {
    public static void main(String[] args) throws IOException {
        FileInputStream fis=new FileInputStream("abc\\sort.txt");
        BufferedReader br=new BufferedReader(new InputStreamReader(fis,"utf-8"));
        ArrayList<String> list=new ArrayList<String>();
        String line=null;
        while((line=br.readLine())!=null) {
            list.add(line);
        }
        br.close();System.out.println(list.size());
        System.out.println(list);
        
        for(int i=0;i<list.size();i++) {
            String str1=list.get(i);
            System.out.println(str1);
            for(int j=i+1;j<list.size()-i;j++) {
                
                String str2=list.get(j);
                System.out.println(str2);
                if(str1.charAt(0)>str2.charAt(0)) {
                    String max;
                    max=str1;
                    System.out.println(max);
                    list.set(i, str2);
                    list.set(j, max);
                    str1=list.get(i);
                }
                System.out.println(list.get(i)+list.get(j));
            }
        }
        for(String k:list) {
            System.out.println(k);
        }
        FileOutputStream fos=new FileOutputStream("abc\\sort.txt");
        BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(fos,"utf-8"));
        for(String i:list) {
            bw.write(i);
            bw.newLine();
        }
        bw.close();
    }
}